import request from '@/utils/request'

export function getMainOwnerGroups(params) {
  return request({
    url: '/exam/group/mainOwner',
    method: 'get',
    params
  })
}

export function getSecondaryOwnerGroups(params) {
  return request({
    url: '/exam/group/secondaryOwner',
    method: 'get',
    params
  })
}

export function getMemberGroups(params) {
  return request({
    url: '/exam/group/member',
    method: 'get',
    params
  })
}

export function getDisabledOrQuitGroups(params) {
  return request({
    url: '/exam/group/disabledOrQuit',
    method: 'get',
    params
  })
}

export function getPendingInvites(params) {
  return request({
    url: '/exam/group/pendingInvites',
    method: 'get',
    params
  })
}

export function applyJoinGroup(data) {
  return request({
    url: '/exam/group/applyJoin',
    method: 'post',
    data
  })
}

export function handleInvite(inviteId, accept) {
  return request({
    url: `/exam/group/handleInvite/${inviteId}`,
    method: 'post',
    params: { accept }
  })
}

export function transferOwnership(groupId, newOwnerId) {
  return request({
    url: `/exam/group/transfer/${groupId}`,
    method: 'post',
    params: { newOwnerId }
  })
}

export function quitGroup(groupId) {
  return request({
    url: `/exam/group/quit/${groupId}`,
    method: 'post'
  })
}

export function enableGroup(groupId, enable) {
  return request({
    url: `/exam/group/enable/${groupId}`,
    method: 'post',
    params: { enable }
  })
}

export function deleteGroup(groupId) {
  return request({
    url: `/exam/group/${groupId}`,
    method: 'delete'
  })
}


// 添加接口
export function addExamGroup(data) {
  return request({
    url: '/exam/group',
    method: 'post',
    data: data
  })
}

export function updateExamGroup(data) {
  return request({
    url: '/exam/group',
    method: 'put',
    data: data
  })
}





// 获取学生参加的考试组列表
export function getStudentGroups(params) {
  return request({
    url: '/exam/group/student/list',
    method: 'get',
    params
  })
}

// 根据邀请码搜索考试组
export function searchGroupByCode(code) {
  return request({
    url: '/exam/group/searchByCode',
    method: 'get',
    params: { code }
  })
}

// 申请加入考试组
export function studentJoinGroup(data) {
  return request({
    url: '/exam/group/student/apply',
    method: 'post',
    data
  })
}


export function quitGroupOfStu(groupId) {
  return request({
    url: `/exam/group/student/quit/${groupId}`,
    method: 'post'
  })
}

export function getStudentApplications(query) {
  return request({
    url: '/exam/group/student/applications',
    method: 'get',
    params: query
  })
}

// 取消申请 (通过考试组Id)
export function cancelApplication(id) {
  return request({
    url: `/exam/group/student/applications/${id}`,
    method: 'delete'
  })
}

// 取消申请 (通过成员Id)
export function cancelApplicationByMemberId(id) {
  return request({
    url: `/exam/group/student/applications/by/member/${id}`,
    method: 'delete'
  })
}





export function getGroupDetail(groupId) {
  return request({
    url: `/exam/group/detail/${groupId}`,
    method: 'get'
  })
}
